﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.ComponentModel;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.ImageOperators;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using AForge.Imaging;
using System.Diagnostics;
using BrainTechLLC.ImageOperatorsNonAForgeDependent;

namespace BrainTechLLC.FilterExtensions
{
    [Serializable]
    public class ImageCalculation : BaseNotifyPropertyChanged, INotifyPropertyChanged
    {
        protected string _CalculationName;
        public Func<CalculationInstance, Color, int, int, double> CalcAction;

        public ImageCalculation() { }

        public ImageCalculation(string calcName, Func<CalculationInstance, Color, int, int, double> calcAction)
        {
            CalcAction = calcAction;
            _CalculationName = calcName;
        }

        public string CalculationName
        {
            get { return _CalculationName; }
        }

        public CalculationInstance Calculate(Bitmap bm)
        {
            CalculationInstance calcInstance = new CalculationInstance(this);
            int width = bm.Width;
            int height = bm.Height;

            for (int n = 0; n < height; n++)
            {
                for (int j = 0; j < width; j++)
                {
                    Color c = bm.GetPixel(j, n);
                    calcInstance.Calculate(c, j, n);
                }
            }

            return calcInstance;
        }

        public static double AverageRedCalc(CalculationInstance instance, Color c, int x, int y)
        {
            return (double)c.R + (((double)c.G + (double)c.B) / 3D);
        }

        public static double SumColors(CalculationInstance instance, Color c, int x, int y)
        {
            return (double)c.R + (double)c.G + (double)c.B;
        }
    }
}

